import { FieldProps } from '@rjsf/utils';
import { SelectionPickField } from './SelectionPickField';
import { EntityInfo } from '@amcax/web-render';
import { makeEntityInfo, makeIdNew } from '@/common/utils';

/**
 * 通过控制拾取类型，从渲染场景中拾取Entity，并通过onChange返回id字符串数组
 */
export function SelectionPickField2({
  formData,
  onChange,
  ...rest
}: FieldProps) {
  const handleChange = (formData: EntityInfo[]) => {
    if (formData) {
      onChange(formData.map(makeIdNew));
    }
  };

  return (
    <SelectionPickField
      formData={formData?.map(makeEntityInfo)}
      onChange={handleChange}
      {...rest}
    />
  );
}
